package com.light.mytext.mycustomview

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.light.mytext.R
import kotlinx.android.synthetic.main.activity_my_remote_control.*

/**
 * 360度平滑摇杆
 */
class MyRemoteControlActivity : AppCompatActivity() {
    var upDirection=0//前进标记
    var turnDirection=0//转弯标记
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_my_remote_control)
        init()
    }
    fun init(){
        //360度平滑摇杆  前进
        remote1.setRudderListener(object : MySurfaceView2.RudderListener {
            override fun isUp(direction: Int) {
                if(upDirection==direction){//去重
                    return
                }
                upDirection=direction
                Log.v("MySurfaceView2", "direction==$direction")
                if(direction==0){
                    Log.v("MySurfaceView2", "前进归位");
                    tv_run.text="前进归位"
                }else if(direction==1){
                    Log.v("MySurfaceView2", "前进")
                    tv_run.text="前进"
                }else{
                    Log.v("MySurfaceView2", "后退")
                    tv_run.text="后退"
                }

            }

            override fun isTurn(direction: Int) {
            }

            override fun onSteeringWheelChanged(cross: Float, longitudinal: Float) {
            }
        })
        //360度平滑摇杆  转弯
        remote2.setRudderListener(object : MySurfaceView2.RudderListener {
            override fun isUp(direction: Int) {
            }

            override fun isTurn(direction: Int) {
                if(turnDirection==direction){//去重
                    return
                }
                turnDirection=direction
                Log.v("MySurfaceView2", "direction==$direction")
                if(direction==0){
                    Log.v("MySurfaceView2", "转向归位")
                    tv_turn.text="转向归位"
                }else if(direction==1){
                    Log.v("MySurfaceView2", "向右转弯")
                    tv_turn.text="向右转弯"
                }else{
                    Log.v("MySurfaceView2", "向左转弯")
                    tv_turn.text="向左转弯"
                }
            }

            override fun onSteeringWheelChanged(cross: Float, longitudinal: Float) {
            }
        })
    }
}